package com.shelly.singleton.type2;

/**
 * @author: Shelly
 * @create: 2023-01-10 16:57:00
 * @describe: 饿汉式-静态代码块
 */
public class Singleton {
    private static final Singleton instance;
    static{
        instance = new Singleton();
    }
    // 私有化构造器
    private Singleton(){}

    // 提供外部调用方法
    public static Singleton getInstance(){
        return instance;
    }

    // 测试
    public static void main(String[] args) {
        Singleton a = Singleton.getInstance();
        Singleton b = Singleton.getInstance();
        System.out.println(a.equals(b));
        System.out.println(a);// 打印地址
        System.out.println(b);
    }
}
